///*     */ package com.iris.egrantweb.struts2.interceptor;
///*     */
///*     */ import com.opensymphony.xwork2.ActionContext;
///*     */ import com.opensymphony.xwork2.ActionInvocation;
///*     */ import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
///*     */ import com.opensymphony.xwork2.util.location.Location;
///*     */ import com.opensymphony.xwork2.util.location.LocationUtils;
///*     */ import freemarker.template.Configuration;
///*     */ import freemarker.template.Template;
///*     */ import java.io.IOException;
///*     */ import java.io.StringWriter;
///*     */ import java.io.Writer;
///*     */ import java.util.ArrayList;
///*     */ import java.util.Date;
///*     */ import java.util.HashMap;
///*     */ import java.util.List;
///*     */ import java.util.Map;
///*     */ import java.util.regex.Pattern;
///*     */ import javax.servlet.ServletContext;
///*     */ import javax.servlet.ServletRequest;
///*     */ import javax.servlet.http.HttpServletRequest;
///*     */ import javax.servlet.http.HttpServletResponse;
///*     */ import org.apache.struts2.RequestUtils;
///*     */ import org.apache.struts2.ServletActionContext;
///*     */ import org.apache.struts2.dispatcher.Dispatcher;
///*     */ import org.slf4j.Logger;
///*     */ import org.slf4j.LoggerFactory;
///*     */ import org.springframework.web.context.WebApplicationContext;
///*     */ import org.springframework.web.context.support.WebApplicationContextUtils;
///*     */ import org.springframework.web.util.WebUtils;
///*     */
///*     */
///*     */
///*     */
///*     */
///*     */ public class ExceptionLogInterceptor
///*     */   extends AbstractInterceptor
///*     */ {
///*     */   private static final long serialVersionUID = -6153263768867359067L;
///*  41 */   private static final Logger log = LoggerFactory.getLogger(ExceptionLogInterceptor.class);
///*     */
///*  43 */   private final Map<Pattern, String> overrides = new HashMap<Pattern, String>();
///*     */
///*     */
///*     */
///*     */
///*     */
///*     */
///*     */
///*     */
///*     */
///*     */
///*     */
///*     */
///*     */   public void init() {
///*  57 */     this.overrides.put(Pattern.compile(".*iPhone.*"), "iphone");
///*  58 */     this.overrides.put(Pattern.compile(".*Android.*"), "iphone");
///*  59 */     this.overrides.put(Pattern.compile(".*Safari.*Pre.*"), "iphone");
///*  60 */     this.overrides.put(Pattern.compile(".*Nokia.*AppleWebKit.*"), "iphone");
///*     */   }
///*     */
///*     */
///*     */
///*     */
///*     */   public String intercept(ActionInvocation invocation) throws Exception {
///*  67 */     String returnValue = null;
///*  68 */     HttpServletRequest request = null;
///*  69 */     HttpServletResponse response = null;
///*     */
///*     */     try {
///*  72 */       ActionContext actionContext = invocation.getInvocationContext();
///*  73 */       request = (HttpServletRequest)actionContext.get("com.opensymphony.xwork2.dispatcher.HttpServletRequest");
///*  74 */       response = (HttpServletResponse)actionContext.get("com.opensymphony.xwork2.dispatcher.HttpServletResponse");
///*  75 */       response.setHeader("Cache-Control", "no-cache, max-age=0");
///*  76 */       String userAgent = request.getHeader("User-Agent");
///*  77 */       if (userAgent != null)
///*     */       {
///*     */
///*  80 */         for (Map.Entry<Pattern, String> entry : this.overrides.entrySet()) {
///*  81 */           if (((Pattern)entry.getKey()).matcher(userAgent).matches()) {
///*  82 */             request.setAttribute("isMobile", "true");
///*  83 */             request.setAttribute("browserType", entry.getValue());
///*     */
///*     */             break;
///*     */           }
///*     */         }
///*     */       }
///*  89 */       returnValue = invocation.invoke();
///*  90 */     } catch (Exception e) {
///*     */
///*     */
/////*  93 */       Long userId = SecurityUtils.getCurrentUserId();
///*     */
///*  95 */       if (e instanceof java.net.SocketException) {
///*  96 */         log.warn(" Exception : " + e.getMessage() + " , user : [ " + userId + " ] , server= " + System.getProperty("weblogic.Name", "") + "class : " + invocation.getProxy().getAction().getClass() + ", method :" + invocation.getProxy().getMethod() + ", time : " + new Date(), e.getMessage());
///*     */
///*     */       }
///*     */       else {
///*     */
///*     */
///* 102 */         e.printStackTrace();
///* 103 */         log.error(" Exception : " + e.getMessage() + " , user : [ " + userId + " ] , REFERER: " + request.getHeader("REFERER") + " ;server= " + System.getProperty("weblogic.Name", "") + "; class : " + invocation.getProxy().getAction().getClass() + ", method :" + invocation.getProxy().getMethod() + ", time : " + new Date() + " requesturl:" + RequestUtils.getServletPath(request) + " ;requestparam: " + WebUtils.getParametersStartingWith((ServletRequest)request, null).toString(), e);
///*     */       }
///*     */
///*     */
///*     */
///*     */
///*     */
///*     */
///*     */
///* 112 */       String ip = request.getHeader("X-Forwarded-For");
///*     */
///* 114 */       if (ip == null || ip.length() == 0) {
///* 115 */         ip = request.getHeader("WL-Proxy-Client-IP");
///*     */       }
///*     */
///* 118 */       if (ip == null || ip.length() == 0) {
///* 119 */         ip = request.getRemoteAddr();
///*     */       }
///*     */
///*     */
///* 123 */       if (ip.indexOf("192.168.2.") == 0 || ip.indexOf("192.168.3.") == 0 || ip.indexOf("192.168.10.") == 0 || ip.indexOf("192.168.15.") == 0 || ip.indexOf("58.60.231.58") == 0) {
///*     */
///*     */
///* 126 */         sendError(request, response, ServletActionContext.getServletContext(), 500, e);
///* 127 */         response.addHeader("loginUser", "tester");
///* 128 */         return null;
///*     */       }
///* 130 */       response.setStatus(500);
///*     */
///*     */
///* 133 */       throw e;
///*     */     }
///*     */
///* 136 */     return returnValue;
///*     */   }
///*     */
///*     */
///*     */
///*     */
///*     */
///*     */
///*     */
///*     */
///*     */
///*     */
///*     */
///*     */
///*     */
///*     */
///*     */
///*     */
///*     */
///*     */
///*     */
///*     */   public void sendError(HttpServletRequest request, HttpServletResponse response, ServletContext ctx, int code, Exception e) {
///*     */     try {
///* 159 */       WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(ctx);
///* 160 */       Configuration cptFreemarkereConfiguration = (Configuration)context.getBean("cptFreemarkereConfiguration");
///* 161 */       Template template = cptFreemarkereConfiguration.getTemplate("error.ftl", "utf-8");
///*     */
///* 163 */       List<Throwable> chain = new ArrayList<Throwable>();
///* 164 */       Throwable cur = e;
///* 165 */       chain.add(cur);
///* 166 */       while ((cur = cur.getCause()) != null) {
///* 167 */         chain.add(cur);
///*     */       }
///*     */
///* 170 */       HashMap<String, Object> data = new HashMap<String, Object>();
///* 171 */       data.put("exception", e);
///* 172 */       data.put("unknown", Location.UNKNOWN);
///* 173 */       data.put("chain", chain);
///* 174 */       data.put("locator", new Dispatcher.Locator());
///*     */
///* 176 */       Writer writer = new StringWriter();
///* 177 */       template.process(data, writer);
///* 178 */       response.setStatus(500);
///* 179 */       response.setContentType("text/html");
///* 180 */       response.getWriter().write(writer.toString());
///* 181 */       response.getWriter().close();
///* 182 */     } catch (Exception exp) {
///*     */
///*     */       try {
///* 185 */         log.debug("Cannot show problem report!", exp);
///*     */
///* 187 */         response.sendError(code, "Unable to show problem report:\n" + exp + "\n\n" + LocationUtils.getLocation(exp));
///*     */       }
///* 189 */       catch (IOException ex) {}
///*     */     }
///*     */   }
///*     */ }
//
//
///* Location:              D:\文件kjt\WEB-INF\lib\egrant-core-2.2.20240205.1659.jar!\com\iris\egrant\web\struts2\interceptor\ExceptionLogInterceptor.class
// * Java compiler version: 6 (50.0)
// * JD-Core Version:       1.1.3
// */